package com.ruiysoft.service.order.mq;

import com.rabbitmq.client.Channel;
import com.ruiysoft.conf.mq.OrderMqConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * Date : 2018/11/29
 *
 * @author WenJialu
 */
@Component
public class TestSubscriber {

//	@RabbitListener(
//			bindings = {
//					@QueueBinding(
//							value = @Queue(value = OrderMqConfig.ORDER_AFTER_OPERATE_QUEUE_NAME,
//									durable = "true",
//									autoDelete = "false"),
//							exchange = @Exchange(value = OrderMqConfig.ORDER_AFTER_OPERATE_EXCHANGE_NAME, autoDelete = "false"),
//							key = OrderMqConfig.ORDER_AFTER_OPERATE_ROUTE_KEY
//					)
//
//			}
//	)
//	@Transactional
//	@RabbitHandler
	public void onMessage(Message message, Channel channel) throws IOException {
		String json = new String(message.getBody(), StandardCharsets.UTF_8);
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		System.err.println(json);
	}

}
